<?php
namespace app\common\service;



use think\Model;

class ShareLogService extends Model
{

    /**
     * （前端回调）添加分享日志记录
     * @param $sid
     * @param $uid
     * @param array $postParam
     * @return array
     */
    public function addShareLog($sid, $uid, $postParam = []){
        $store_name = db('store')->where(['store_id' => $sid])->value('store_name');
        $user_info = db('user_integral ui')
                    ->field('u.user_name,u.user_mobile,u.user_nickname,u.user_headimgurl,ui.distribution')
                    ->join('user u', 'u.user_id = ui.userid')
                    ->where(['ui.sid' => $sid, 'ui.userid' => $uid])
                    ->find();
        if(empty($user_info)){
            return ['status' => 0, 'msg' => '用户不存在'];
        }

//        $share_url = $postParam['share_url'];

        $inser_data = [];
        $inser_data['sid'] = $sid;
        $inser_data['store_name'] = $store_name;
        $inser_data['uid'] = $uid;
        $inser_data['user_name'] = $user_info['user_name'];
        $inser_data['user_mobile'] = $user_info['user_mobile'];
        $inser_data['user_nickname'] = $user_info['user_nickname'];
        $inser_data['user_headimgurl'] = $user_info['user_headimgurl'];
        $inser_data['distribution'] = $user_info['distribution'];
        $inser_data['share_type'] = $postParam['share_type'];
        $inser_data['message_type'] = $postParam['message_type'];
        $inser_data['share_url'] = $postParam['share_url'];
        $inser_data['remark'] = $postParam['remark'] ?? '';
        $inser_data['create_time'] = time();
        $inser_data['create_date'] = date('Y-m-d H:i:s', time());
        $inser_data['data_id'] = $postParam['data_id'];
        $inser_data['cid'] = $postParam['cid'];
        $inser_data['m'] = $postParam['m'];
        $inser_data['c'] = $postParam['c'];
        $inser_data['a'] = $postParam['a'];

        $result = db('share_log')->insertGetId($inser_data);
        return $result > 0 ? ['status' => 1, 'msg' => '添加成功'] : ['status' => 0, 'msg' => '添加失败'];
    }

}